//
// Created by t400 on 2016/11/18.
//

#include <memory.h>
#include "index.h"
#include "juxin_encrypt.h"

JNIEXPORT jstring JNICALL Java_com_noble_library_utils_JniUtil_GetEncryptString
        (JNIEnv *env, jclass jcls, jstring jstr){

    char *cstr = (char *) env->GetStringUTFChars(jstr, JNI_FALSE);
    const char *strResult = GetEncryptString(cstr);
    SAFE_FREE(cstr);
    return env->NewStringUTF(strResult);
}

JNIEXPORT jbyteArray JNICALL Java_com_noble_library_utils_JniUtil_GetDecryptString
        (JNIEnv *env, jclass jcls, jstring jstr){
    char *cstr = (char *) env->GetStringUTFChars(jstr, JNI_FALSE);
    const char *strResult = GetDecryptString(cstr);
    jbyteArray bytes = env->NewByteArray((jsize) strlen(strResult) );
    env->SetByteArrayRegion(bytes, 0, (jsize) strlen(strResult), (jbyte*)strResult);
    SAFE_FREE(cstr);
    return bytes;
}
